function center(e){
	var _this = $(e);
	_this.css({ 
		position:'absolute', 
		left: ($(window).width() - _this.outerWidth())/2, 
		top: ($(window).height() - _this.outerHeight())/2 + $(document).scrollTop() 
	}); 
}
function centerY(e,y){
	var _this = $(e);
	_this.css({ 
		position:'absolute', 
		left: ($(window).width() - _this.outerWidth())/2, 
		top: y
	}); 
}

$(function(){
	centerY("#message");

});

//刷新table
function reloadTable(tableId,url,params) {
	
	$("#" + tableId).jqGrid('setGridParam', {
	    url : url,
	    datatype:'json',
	    postData : params, 
	    page : 1
	}).trigger("reloadGrid"); //重新载入
}


//公共js请求拦截器
//主要用于处理弹出提示信息，然后调用自己页面的函数进行相关提交或者更新操作
function submitFilter(callback) {
	
	var index = parent.layer.msg('正在提交请稍候......', {icon: 16,time: 200000,shade : [0.5 , '#000' , true]});
	callback(index);
}

//公共form表单提交
function formSubmit(formId,data) {

	var index = parent.layer.msg('正在提交请稍候......', {icon: 16,time: 200000,shade : [0.5 , '#000' , true]});

	if(data) {
		$("#" + formId).ajaxSubmit({
	        dataType: "json",
	        data: data,
	        success: function (json) {
	        	
	        	parent.layer.close(index);
	        	
	        	if(json.msg) {
            		layer.msg(json.msg, {icon: 1});
            	} else {
            		layer.msg('信息提交成功', {icon: 1});
            	}
	        	
	            if(json.code == 0) {
	            	setTimeout(function(){
	            		window.parent.location.reload();
	            		parent.layer.closeAll();
	            	}, 1000);
	            	
	            }
	        },
	        error:function() {
	        	layer.msg('发生错误', {icon: 5});
	        }
	    });
		
	} else {
		
		$("#" + formId).ajaxSubmit({
	        dataType: "json",
	        success: function (json) {
	        	
	        	parent.layer.close(index);
	        	
	            var code = json.code;
	            if(code == 0){
	            	layer.msg('信息提交成功', {icon: 1});
	            	 setTimeout(function(){
	                 	window.parent.location.reload();
	                 	parent.layer.closeAll();
	                 }, 1000); 
	            }else{
	            	layer.msg('信息提交发生错误：' + json.msg, {icon: 5});
	            }
	        },
	        error:function() {
	        	layer.msg('信息提交发生错误', {icon: 5});
	        }
	    });
	}
}


//随机数
//1-成功；0-失败
function sysFaceRandom(flag) {
	
	return (96 + Math.random()*4).toFixed(2) + "%";
}


//模糊下拉查询用户信息
function ffindPersonList(inputId){
	$("#" + inputId).bsSuggest({
		clearable: true,
		url : ctx + "/unitfiling/suggest?keywords=",
		idField : "id", //id字段
		keyField : "name",
		effectiveFields : [ "name" ],
		emptyTip: '查询结果给为空...',
		listStyle: {
	        'padding-top': 0,
	        'height': '175px',
	        'max-width': '800px',
	        'overflow': 'auto',
	        'transition': '0.3s',
	        '-webkit-transition': '0.3s',
	        '-moz-transition': '0.3s',
	        '-o-transition': '0.3s'
	    }, 
	}).on("onSetSelectValue", function(e, keyword) { //选择时
		alert(keyword.id);
	})
}


function S4() {
	return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

 function guid() {
    var uuid = (S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4());
    return uuid;
 }
 
 var LODOP; //声明为全局变量 
	
 //创建打印信息
 function CreatePrintPage(title,dataFormId,qrcode) {
	LODOP=getLodop();  
	//LODOP.PRINT_INITA(10,17,754,450,title);
	LODOP.ADD_PRINT_HTML(50,150,754,450,"<font color='black' size='5px'>" + title + "</font>\n");
	//LODOP.ADD_PRINT_IMAGE(100,100,200,200,document.getElementById("fanh").innerHTML);
	//LODOP.ADD_PRINT_BARCODE(20,580,110,110,"QRCode","");
	//
	LODOP.ADD_PRINT_BARCODE(20,580,110,110,"QRCode",qrcode);
	LODOP.SET_PRINT_STYLEA(1,"QRCodeVersion",14);
	//LODOP.ADD_PRINT_IMAGE(28,49,171,153,"<img border='0' src='http://static15.photo.sina.com.cn/middle/4fe4ba17t993d651b55ce&690' />");
	/*LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
	LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
	LODOP.SET_PRINT_STYLEA(0,"Horient",2);
	LODOP.ADD_PRINT_TABLE(63,36,700,330, $("#printDataForm").html());
	LODOP.SET_PRINT_STYLEA(0,"FontSize",15);
	LODOP.SET_PRINT_STYLEA(0,"ItemType",4);
	LODOP.SET_PRINT_STYLEA(0,"Horient",3);
	LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
	LODOP.ADD_PRINT_LINE(53,23,52,725,0,1);
	LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
	LODOP.SET_PRINT_STYLEA(0,"Horient",3);
	LODOP.ADD_PRINT_LINE(414,23,413,725,0,1);
	LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
	LODOP.SET_PRINT_STYLEA(0,"Horient",3);
	LODOP.SET_PRINT_STYLEA(0,"Vorient",1);
	LODOP.ADD_PRINT_TEXT(421,37,144,22,"");
	LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
	LODOP.SET_PRINT_STYLEA(0,"Vorient",1);
	//LODOP.ADD_PRINT_TEXT(421,542,165,22,"第#页/共&页");
	LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
	LODOP.SET_PRINT_STYLEA(0,"Horient",1);
	LODOP.SET_PRINT_STYLEA(0,"Vorient",1);*/
	LODOP.ADD_PRINT_TABLE(120,18,"100%","100%",/* $("#" + dataFormId).html()*/document.getElementById(dataFormId).innerHTML);
 }
 //预览
 function Preview(title,dataFormId,qrcode) {		
	CreatePrintPage(title,dataFormId,qrcode);
  	LODOP.PREVIEW();		
 }

 //直接打印
 function Print(title,dataFormId,qrcode) {		
	CreatePrintPage(title,dataFormId,qrcode);
  	LODOP.PRINT();		
 }

 //根据坐标查看地图并标记
 function geographic(lng,lat) {
		layer.open({
			type : 2,
			title : '地图查看',
			shadeClose : true,
			shade : 0.5,
			area : [ '800px', '550px' ],
			content : ctx +'/warehouse/geographic?lng='+lng+'&lat=' +lat//iframe的url
		});
	}

 

 